<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const arr = [1, 2, 3, [4, 5], [6, 7, [8, 9]]]
    // one
    const flatten1 = arr => arr.flat(Infinity)
    console.log(flatten1(arr));    
    // two
    const flatten2 = arr => arr.toString().split(',').map(item => Number(item))
    console.log(flatten2(arr));   

    // three
    const flatten3 = arr => {
      while (arr.some(Array.isArray)) {
        arr = [].concat(...arr);
      }
      return arr
    }
    console.log(flatten3(arr))

    // four
    const flatten4 = arr => {
      return arr.reduce((result, item) => {
        return result.concat(Array.isArray(item) ? flatten4(item) : item)
      }, [])
    }
    console.log(flatten4(arr))

    // 仅可打平二维数组
    const flatten5 = arr => {
      return arr.reduce((result, item) => {
        return result.concat(item)
      }, [])
    }
    console.log(flatten5(arr))
  </script>
</body>

</html>